﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SIS.BLL;
using SIS.UI;
using SIS.ENT;
using System.Globalization;

public partial class Employee_EmployeeTimeSheetList: System.Web.UI.Page
{
    #region "Private Variabels"
    public Common _common = new Common();
    #endregion

    #region "Event"

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            _common.LoadSchoolDDL(ddlSchoolList, string.Empty);
            _common.LoadEmployeeDDLWithBlank(ddlEmployee, Convert.ToInt32(ddlSchoolList.SelectedValue), string.Empty);
            txtStartDate.Text = DateTime.Today.ToString("dd/MM/yyyy");
            txtEndDate.Text = DateTime.Today.ToString("dd/MM/yyyy");
        }
    }

    protected void btnShowEmployeeAttandance_Click(object sender, EventArgs e)
    {
        int SchoolKey = Convert.ToInt32(ddlSchoolList.SelectedValue);
        string EmployeeProfileKey = string.Empty;
        if (ddlEmployee.SelectedValue == "0")
        {
            EmployeeProfileKey = "%";
        }
        else
        {
            EmployeeProfileKey = ddlEmployee.SelectedValue;
        }

        string StartDate = txtStartDate.Text;
        var dtfi1 = new DateTimeFormatInfo { ShortDatePattern = "dd-MM-yyyy", DateSeparator = "-" };
        DateTime objStartDate = Convert.ToDateTime(StartDate, dtfi1);
        string EndDate = txtEndDate.Text;
        var dtfi2 = new DateTimeFormatInfo { ShortDatePattern = "dd-MM-yyyy", DateSeparator = "-" };
        DateTime objEndDate = Convert.ToDateTime(EndDate, dtfi2);

        EmployeeTimeSheetTableList lList = new EmployeeTimeSheetTableList();
        lList = EmployeeTimeSheetTableManager.GetList(SchoolKey, EmployeeProfileKey, objStartDate, objEndDate);
        grvEmployeeAttandance.DataSource = lList;
        grvEmployeeAttandance.DataBind();
    }

    protected void ddlSchoolList_SelectedIndexChanged(object sender, EventArgs e)
    {

    }

    protected void grvEmployeeAttandance_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        long EmployeeAttandanceKey = Convert.ToInt32(grvEmployeeAttandance.DataKeys[1].Value);
        //int UserAccountkey = Convert.ToInt32(grvEmployeeAttandance.DataKeys[e.RowIndex].Value);

        EmployeeTimeSheetTableManager.Delete(EmployeeAttandanceKey);
    }

    protected void grvEmployeeAttandance_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (grvEmployeeAttandance.SelectedIndex >= 0)
        {
            DataKey _selectedDataKey = grvEmployeeAttandance.SelectedDataKey;
            int _EmployeeProfileKey = Convert.ToInt32(_selectedDataKey[0]);
            int _UserAccountKey = Convert.ToInt32(_selectedDataKey[1]);
            if (_EmployeeProfileKey > 0 && _UserAccountKey > 0)
            {
                lblSelectedEmployeeAttandanceKey.Text = _EmployeeProfileKey.ToString();
                lblSelectedEmployeeUserAccountKey.Text = _UserAccountKey.ToString();
            }
        }
    }

    protected void btnAddAttndance_Click(object sender, EventArgs e)
    {
        Response.Redirect("EmployeeTimeSheetEntry.aspx?SchoolKey=" + ddlSchoolList.SelectedValue);
    }

    protected void grvEmployeeAttandance_OnRowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType != DataControlRowType.Header && e.Row.RowType != DataControlRowType.Footer && e.Row.RowType == DataControlRowType.DataRow)
        {
            int index = e.Row.RowIndex;
            CheckBox chkStatus = (CheckBox)e.Row.FindControl("chkStatus");
            bool AttandanceStatus = Convert.ToBoolean(DataBinder.Eval(e.Row.DataItem, "TimeSheetStatus"));
            if (AttandanceStatus == true)
            {
                chkStatus.Checked = true;
            }
            else
            {
                chkStatus.Checked = false;
            }
        }
    }

    #endregion
}